# -*- coding:utf-8 -*-
import random
from qcloudsms_py import SmsSingleSender
from luffy_api.utils.logger import log
from luffy_api.libs.tx_sms import settings


# 生成4位随机验证码
def get_code():
    return random.randint(1000, 9999)

# print(type(random.randint(1000,9999)))
def send_message(phone, code):
    ssender = SmsSingleSender(settings.appid, settings.appkey)
    params = [code]
    try:
        result = ssender.send_with_param(86, phone, settings.template_id, params, sign=settings.sms_sign, extend="", ext="")
        if result.get('result') == 0:
            return True
        else:
            return False
    except Exception as e:
        log.error('短信发送失败，%s' % str(e))
